name: Cron update
on:
  workflow_dispatch:
  schedule:
    #        ┌───────────── minute (0 - 59)
    #        │  ┌───────────── hour (0 - 23)
    #        │  │ ┌───────────── day of the month (1 - 31)
    #        │  │ │ ┌───────────── month (1 - 12 or JAN-DEC)
    #        │  │ │ │ ┌───────────── day of the week (0 - 6 or SUN-SAT)
    #        │  │ │ │ │
    - cron: '42 2 * * SUN-WED'
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#defaultsrun
defaults:
  run:
    shell: bash --noprofile --norc -exo pipefail {0}
concurrency:
  group: cron-${{ github.head_ref || github.run_id }}
  cancel-in-progress: true
jobs:
  update-actions:
    runs-on: 'ubuntu-latest'
    name: Ratchet update
    if: "github.repository == 'bentoml/OpenLLM'" # Don't run on fork repository
    env:
      ACTIONS_TOKEN: ${{ secrets.OPENLLM_PAT }}
    steps:
      - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # ratchet:actions/checkout@v4.1.1
        with:
          fetch-depth: 0
      - name: Install jq and curl
        run: sudo apt-get install -y jq curl
      - name: Import bot's GPG key for signing commits
        id: import-gpg-key
        uses: crazy-max/ghaction-import-gpg@01dd5d3ca463c7f10f7f4f7b4f177225ac661ee4 # ratchet:crazy-max/ghaction-import-gpg@v6
        with:
          gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
          passphrase: ${{ secrets.GPG_PASSPHRASE }}
          git_config_global: true
          git_user_signingkey: true
          git_commit_gpgsign: true
      - name: Locking dependencies
        run: bash ./tools/update-actions.sh
      - name: Create a PR
        uses: peter-evans/create-pull-request@153407881ec5c347639a548ade7d8ad1d6740e38 # ratchet:peter-evans/create-pull-request@v5.0.2
        env:
          GIT_AUTHOR_NAME: ${{ steps.import-gpg-key.outputs.name }}
          GIT_AUTHOR_EMAIL: ${{ steps.import-gpg-key.outputs.email }}
          GIT_COMMITTER_NAME: ${{ steps.import-gpg-key.outputs.name }}
          GIT_COMMITTER_EMAIL: ${{ steps.import-gpg-key.outputs.email }}
          BRANCH_NAME: cron/ratchet
        with:
          title: 'ci: update lock actions [generated]'
          commit-message: 'cron: ratchet update'
          branch-suffix: timestamp
          signoff: true
          delete-branch: true
          reviewers: aarnphm
          author: ${{ env.GIT_AUTHOR_NAME }} <${{ env.GIT_AUTHOR_EMAIL }}>
          branch: ${{ env.BRANCH_NAME }}
